package com.poetize.plus.entity.vo.page;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Sort;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author zuosy
 * @Date 2024/3/30 16:23
 **/
public record SortPageVO(
        @Schema(description = "分类id")
        Long sortId,
        @Schema(description = "分类名称")
        String sortName,
        @Schema(description = "分类简介")
        String sortDescription,
        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime
) {

    /**
     * 集合数据转分页集合
     * @param sortList
     * @return
     */
    public static List<SortPageVO> convertPageList(List<Sort> sortList) {
        List<SortPageVO> result = new ArrayList<>();
        sortList.forEach(sort -> {
            SortPageVO vo = new SortPageVO(
                    sort.getSortId(),
                    sort.getSortName(),
                    sort.getSortDescription(),
                    sort.getCreateTime());
            result.add(vo);
        });
        return result;
    }
}
